package com.slwish.xty.ui.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.slwish.common.base.PresenterToolbarActivity;
import com.slwish.xty.R;
import com.slwish.xty.entity.CreditPublicityInfoModel;
import com.slwish.xty.mvp.contract.CreditPublicityContract;
import com.slwish.xty.mvp.presenter.CreditPublicityPresenter;

import java.util.List;

import butterknife.BindView;

public class CreditPublicityInfoActivity extends PresenterToolbarActivity<CreditPublicityContract.Presenter> implements CreditPublicityContract.View {
    @BindView(R.id.ll)
    LinearLayout ll;


    @Override
    protected int getLayoutId() {
        return R.layout.act_credit_publicity_info;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        setTitle(R.string.credit_publicity_title);

    }

    @Override
    protected void initData() {
        super.initData();
        mPresenter.getpublicityInfo(mContext);
    }

    @Override
    public void getInfoSuccess(CreditPublicityInfoModel model) {
        List<CreditPublicityInfoModel.CreditPublicity> dlList = model.getData();
        for (CreditPublicityInfoModel.CreditPublicity models : dlList) {
            final LinearLayout llContent = new LinearLayout(mContext);
            llContent.setOrientation(LinearLayout.VERTICAL);
            View miaView = LayoutInflater.from(mContext).inflate(R.layout.view_ll, ll, false);
            TextView tv = miaView.findViewById(R.id.tv_msg);
            final ImageView iv = miaView.findViewById(R.id.iv);
            tv.setText(models.getTitle());
            ll.addView(miaView);
            miaView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (llContent.getVisibility() == View.VISIBLE) {
                        llContent.setVisibility(View.GONE);
                        iv.setImageResource(R.mipmap.xiala_two);
                    } else {
                        llContent.setVisibility(View.VISIBLE);
                        iv.setImageResource(R.mipmap.shouhui);
                    }
                }
            });
            List<CreditPublicityInfoModel.CreditPublicity.ListBean> list = models.getList();
            if (list!=null&&list.size()>=0)
            for (int i = 0; i < list.size(); i++) {
                View contentView = LayoutInflater.from(mContext).inflate(R.layout.view_ll_child, ll, false);
                LinearLayout tablelayout =contentView.findViewById(R.id.tablelayout);
//                if (i % 2 == 0) {
                    tablelayout.setBackgroundColor(i % 2 == 0?getResources().getColor(R.color.space_color1):getResources().getColor(R.color.space_color2));
//                } else {
//                    tablelayout.setBackgroundColor(getResources().getColor(R.color.space_color2));
//                }
                TextView tv_message = contentView.findViewById(R.id.tv_msg);
                TextView tv_content = contentView.findViewById(R.id.tv_content);
                tv_message.setText(list.get(i).getName());
                tv_content.setText(list.get(i).getValue());
                llContent.addView(contentView);
            }
            llContent.setVisibility(View.GONE);
            ll.addView(llContent);
        }

    }

    @Override
    protected CreditPublicityContract.Presenter initPresenter() {
        return new CreditPublicityPresenter(this);
    }
}
